package com.cuihanyu.newuniversityover.fragment;

import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.cuihanyu.newuniversityover.R;
import com.cuihanyu.newuniversityover.activity.LoginActivity;
import com.cuihanyu.newuniversityover.base.BaseFragment;
import com.cuihanyu.newuniversityover.util.SPUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;


/**
 * Created by 崔汉宇 on 2017/8/7.
 */

public class My_Fragment extends BaseFragment {
    @BindView(R.id.MyNote)
    LinearLayout mMyNote;
    @BindView(R.id.back_ImageView)
    ImageView mBack_ImageView;
    @BindView(R.id.MyDY)
    LinearLayout mMyDY;
    @BindView(R.id.MySee)
    LinearLayout mMySee;
    @BindView(R.id.MyMessage)
    LinearLayout mMyMessage;
    @BindView(R.id.BindingPhone)
    LinearLayout mBindingPhone;
    @BindView(R.id.settting)
    LinearLayout mSettting;
    @BindView(R.id.Customer_service)
    LinearLayout Customer_service;
    @BindView(R.id.DL)
    TextView mDL;
    @BindView(R.id.Name_TextView)
    TextView mName_TextView;
    private Intent intent;
    private String name;

    @Override
    public View initView() {
        View view = View.inflate(activity, R.layout.fragment_my, null);
        ButterKnife.bind(this, view);
        intent = new Intent();
        name = (String) SPUtils.get(activity, "Name", "");
        if (!name.isEmpty()) {
            mDL.setVisibility(View.GONE);
            mName_TextView.setVisibility(View.VISIBLE);
            mName_TextView.setText(name);
        }
        return view;
    }
    //      登录      我的笔记    我的订阅    我的观看记录  我的消息    绑定手机号           设置
    @OnClick({R.id.DL,R.id.MyNote,R.id.MyDY,R.id.MySee,R.id.MyMessage,R.id.BindingPhone,R.id.settting,R.id.back_ImageView,R.id.Customer_service})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.DL:
                intent.setClass(activity, LoginActivity.class);
                this.startActivityForResult(intent,1);
                break;
            case R.id.MyNote:
                LoginListener("MyNote");
                break;
            case R.id.MyDY:
                LoginListener("MyDY");
                break;
            case R.id.MySee:
                LoginListener("MySee");
                break;
            case R.id.MyMessage:
                LoginListener("MyMessage");
                break;
            case R.id.BindingPhone:
                LoginListener("BindingPhone");
                break;
            case R.id.Customer_service:
                String url = "mqqwpa://im/chat?chat_type=wpa&uin=" +
                        //qq号
                        756426523 + "";
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                break;
            case R.id.settting:
                LoginListener("settting");
                break;
            case R.id.back_ImageView:
                activity.finish();
                break;
        }
    }

    private void LoginListener(String myNote) {
        if (!mName_TextView.getText().toString().isEmpty()&&
                !SPUtils.get(activity,"Phone","").toString().isEmpty()){
            switch (myNote){
                case "MyNote":
                    Toast.makeText(activity,"该功能正在更新中~",Toast.LENGTH_SHORT).show();
                    break;
                case "MyDY":
                    Toast.makeText(activity,"该功能正在更新中~",Toast.LENGTH_SHORT).show();
                    break;
                case "MySee":
                    Toast.makeText(activity,"下次更新呈现",Toast.LENGTH_SHORT).show();
                    break;
                case "MyMessage":
                    Toast.makeText(activity,"暂无消息",Toast.LENGTH_SHORT).show();
                    break;
                case "BindingPhone":
                    Toast.makeText(activity,"手机号已绑定",Toast.LENGTH_SHORT).show();
                    break;
            }
        }else {
            Toast.makeText(activity,"请您先登录帐号！",Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode){
            case 1:
                mDL.setVisibility(View.GONE);
                mName_TextView.setVisibility(View.VISIBLE);
                mName_TextView.setText(data.getStringExtra("Name"));
                break;
        }
    }
}
